package dane.brown.sql.checker.service.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@Component
@ConfigurationProperties(prefix = "print") // 配置前缀
public class PrintConfigProperties {
    String path;
    String type;
    
    /**
     * 获取实际的文件路径，处理其中的通配符
     * 支持的通配符：
     * {yyyy} - 四位年份
     * {MM} - 月份
     * {dd} - 日期
     * {HH} - 小时
     * {mm} - 分钟
     * {ss} - 秒
     *
     * @return 实际的文件路径
     */
    public String getActualPath() {
        String actualPath = path;
        if (actualPath != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
            actualPath = actualPath.replace("{yyyy}", sdf.format(new Date()));
            
            sdf = new SimpleDateFormat("MM");
            actualPath = actualPath.replace("{MM}", sdf.format(new Date()));
            
            sdf = new SimpleDateFormat("dd");
            actualPath = actualPath.replace("{dd}", sdf.format(new Date()));
            
            sdf = new SimpleDateFormat("HH");
            actualPath = actualPath.replace("{HH}", sdf.format(new Date()));
            
            sdf = new SimpleDateFormat("mm");
            actualPath = actualPath.replace("{mm}", sdf.format(new Date()));
            
            sdf = new SimpleDateFormat("ss");
            actualPath = actualPath.replace("{ss}", sdf.format(new Date()));
        }
        return actualPath;
    }
}